package com.huabo.monitor.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hbfk.entity.DealUserToken;
import com.hbfk.entity.TblStaffUtil;
import com.hbfk.util.JsonBean;
import com.huabo.monitor.entity.TblReport;
import com.huabo.monitor.service.PjbgService;
import com.huabo.monitor.util.ConstClass;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author：yhr
 * @date:2022-09-17 22:55
 * @description:
 */

@RestController
@Slf4j
@Api(value = "内控合规报告-自定义报告", tags = {"内控合规报告-自定义报告所有接口"})
@RequestMapping(value = "/nbkz/zdybg")
public class ZdybgController {


    @Resource
    PjbgService pjbgService;

    String type="nk_zdy";


    @ApiOperation("自定义评价报告-主页")
    @GetMapping(value = "/nkbg/list")

    public JsonBean listnkbg(
            @ApiParam(name = "pageNumber", value = "pageNumber", defaultValue = "1") @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,

            @ApiParam(name = "name", value = "报告名称") @RequestParam(value = "name", required = false)String name,
            @ApiParam(name = "startDate", value = "开始日期") @RequestParam(value = "startDate", required = false)String startDate,
            @ApiParam(name = "endDate", value = "结束日期") @RequestParam(value = "endDate", required = false)String endDate,
            @ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token
    ) throws Exception {
        if (!ConstClass.checkToken(token)) {
            return ConstClass.tokenFailure();
        }
        TblStaffUtil user = DealUserToken.parseUserToken(token);
        IPage<TblReport> page = new Page<>(pageNumber, ConstClass.DEFAULT_SIZE);
        page = pjbgService.findAll(pageNumber,name,startDate,endDate, type, user.getCurrentOrg().getOrgid());

        Map<String, Object> mv = new LinkedHashMap<>();

        mv.put("name", name);
        mv.put("startDate", startDate);
        mv.put("endDate", endDate);

        mv.put("pageBean", page);

        return new JsonBean(200, "success", mv);

    }
}
